package com.xc.ksxt;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ReadDocxFile2 {
    public static void main(String[] args) throws Exception {

        try {
            // 指定输入和输出文件路径
            String inputFilePath = "D:\\文档\\公司资料\\项目资料\\中山大学公共卫生学院\\讯度模版.docx";
            String outputFilePath = "d:\\log\\path_to_output_html_file.html";
            String images="d:\\log\\images\\media";
            // 构建Pandoc转换命令
            String command = "cmd.exe /c pandoc  "  + inputFilePath + " -o "+outputFilePath+" --mathml --mathml --extract-media=d:\\log\\images";
            System.out.println("command = " + command);
            // 执行Pandoc命令
            Process process = Runtime.getRuntime().exec(command);
            // 读取并打印Pandoc执行的输出（主要用于监控转换过程中的信息或错误）
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            reader.close();
            String content = new String(Files.readAllBytes(Paths.get(outputFilePath)), StandardCharsets.UTF_8);
            // 替换指定字符串
            String modifiedContent = content.replace(".wmf", ".png");
            // 将修改后的内容写回文件
            Files.write(Paths.get(outputFilePath), modifiedContent.getBytes(StandardCharsets.UTF_8));
            System.out.println("文件内容替换完成。");
            // 等待Pandoc进程完成
            process.waitFor();
            System.out.println("转换完成！");

            SvgToPngUtil.batchWmfToPng(images);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}